﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QQ2564874169.Core.ORM;
using QQ2564874169.Core.ORM.Sqlserver;

namespace Tests.RelationalSql
{
    [TestClass]
    public class 实体查询操作: BaseTest
    {
        private IDbEntityQuery entityQuery(ISql sql)
        {
            return new MssqlEntityQuery(sql);
        }

        [TestMethod]
        public void 查询类型dynamic()
        {
            Test<dynamic>();
        }

        private void Test<T>()
        {
            Console.WriteLine(typeof(T));
        }

        [TestMethod]
        public void Count()
        {
            using (var sql = new MockSql())
            {
                sql.Before += (s, e) =>
                {
                    ShowArgs(e);
                };
                sql.Rs = 3;
                var query = entityQuery(sql);
                var list = query.Count(new TestEntity() { Id = 2 });
                Assert.AreEqual(sql.Rs, list);
            }
        }

        [TestMethod]
        public void Get()
        {
            using (var sql = new MockSql())
            {
                sql.Before += (s, e) =>
                {
                    ShowArgs(e);
                };
                sql.Rs = new TestEntity();
                var query = entityQuery(sql);
                var list = query.Get(new TestEntity() { Id = 1 });
                Assert.AreEqual(sql.Rs, list);
            }
        }

        [TestMethod]
        public void Gets()
        {
            using (var sql = new MockSql())
            {
                sql.Before += (s, e) =>
                {
                    ShowArgs(e);
                };
                sql.Rs = new List<TestEntity>();
                var query = entityQuery(sql);
                var list = query.Gets(new TestEntity() { Id = 1 });
                Assert.AreEqual(sql.Rs, list);
            }
        }
    }
}
